package gcj2011.round1b;

import java.util.ArrayList;
import java.util.List;

import common.AbstractRunner;
import common.AbstractRunner.SIZE;

public class C extends AbstractRunner {
	
	static class Vertex {
		int number;
		int mark;
		ArrayList<Vertex> link = new ArrayList<Vertex>();
		public Vertex(int number) {
			super();
			this.number = number;
			
		}		
		
		
	}
	static class Cycle {
		List<Vertex> vertices;
	}
	
	Vertex[] vertices;
	ArrayList<Cycle> cycles;
	
	@Override
	public void handleCase(int caseNumber) throws Exception {
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		vertices = new Vertex[n];
		cycles = new ArrayList<Cycle>();
		
		for (int i=0; i<n; i++) {
			vertices[i] = new Vertex(i);			
		}
		for (int i=0; i<n; i++) {
			vertices[i].link.add(vertices[(n+i-1)%n]);
			vertices[i].link.add(vertices[(i+1)%n]);		
		}
		
		int vstart[] = new int[m];
		for (int i=0; i<m; i++) {
			vstart[i] = scanner.nextInt()-1;			
		}
		for (int i=0; i<m; i++) {
			int vend = scanner.nextInt()-1;
			vertices[vstart[i]].link.add(vertices[vend]);
			vertices[vend].link.add(vertices[vstart[i]]);
		}
		
		
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		new C().init(SIZE.test).execute();
	}

}
